<template>
  <div class="app-container">
    <el-form :model="form" ref="form" :inline="true">
      <el-form-item label="售后类型" prop="handleType">
        <el-select v-model="form.handleType" filterable clearable>
          <el-option
            v-for="item in dict.type.ims_after_sale_handle_type"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="售后状态" prop="status">
        <el-select v-model="form.status" filterable clearable>
          <el-option
            v-for="item in dict.type.ims_after_sale_order_status"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
       <el-input v-model="form.customerName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="收件人" prop="recipient">
        <el-input v-model="form.recipient" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
    >
      <el-table-column type="index" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ (form.pageNum - 1) * form.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="orderNo" label="售后单号" align="center">
        <template slot-scope="scope">
          <el-link type="primary" @click="detailRow(scope.row)">{{ scope.row.orderNo }}</el-link>
        </template>
      </el-table-column>
      <el-table-column prop="reOrderNo" label="销售单号" align="center"/>
      <el-table-column prop="customerName" label="客户名称" align="center" width="100"/>
      <el-table-column prop="recipient" label="收件人" align="center" width="100"/>
      <el-table-column prop="auditUserName" label="审核人" align="center" width="100"/>
      <el-table-column prop="handleType" label="售后类型" align="center" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ims_after_sale_handle_type" :value="scope.row.handleType"/>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" align="center" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ims_after_sale_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column prop="returnPrice" label="退款金额(元)" align="center" width="100"/>
      <el-table-column prop="content" label="退/换货内容" align="center"/>
      <el-table-column prop="returnExpressName" label="快递公司" align="center" width="100"/>
      <el-table-column prop="returnExpressNo" label="快递单号" align="center" width="120"/>
      <el-table-column prop="createTime" label="创建时间" align="center" width="140"/>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['ims:saleAfter:log']"
            type="text"
            @click="logRow(scope.row)"
          >记录
          </el-button>
          <el-button
            v-hasPermi="['ims:saleAfter:pay']"
            v-if="scope.row.status==90"
            type="text"
            @click="updateRow(4,scope.row)"
          >支付
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="total"
      :page.sync="form.pageNum"
      :limit.sync="form.pageSize"
      @pagination="getList"
    />
    <logDialog ref="logDialog"></logDialog>
    <detailDialog ref="detailDialog"></detailDialog>
    <approveDialog ref="approveDialog" @ok="handleQuery"></approveDialog>
  </div>
</template>

<script>
import logDialog from "./logDialog.vue";
import detailDialog from "./detailDialog.vue";
import approveDialog from "./approveDialog.vue";
import {listSaleAfter, cancelSaleAfter,inSaleAfter} from "@/api/imsMng";

export default {
  components:{detailDialog,approveDialog,logDialog},
  dicts:['ims_after_sale_handle_type','ims_after_sale_order_status'],
  data() {
    return {
      loading: false,
      list: [],
      form: {
        handleType: "",
        status: "",
        customerName: "",
        recipient: "",
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      this.handleQuery()
    },
    handleQuery() {
      this.form.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('form')
      this.handleQuery()
    },
    getList() {
      this.loading = true
      listSaleAfter(this.form).then(res => {
        this.list = res.rows
        this.total = res.total
      }).finally(e => {
        this.loading = false
      })
    },
    logRow(row){
      this.$refs.logDialog.show(row)
    },
    detailRow(row){
      this.$refs.detailDialog.show(row)
    },
    inRow(row){
      this.$modal.confirm('是否确定入库').then(() => {
        inSaleAfter({afterSaleId: row.afterSaleId}).then(res => {
          this.$message.success('入库成功')
          this.handleQuery()
        })
      })
    },
    cancelRow(row){
      this.$modal.confirm('是否确定取消').then(() => {
        cancelSaleAfter({afterSaleId: row.afterSaleId}).then(res => {
          this.$message.success('取消成功')
          this.handleQuery()
        })
      })
    },
    updateRow(flag,row) {
      let form=JSON.parse(JSON.stringify(row))
      this.$refs.approveDialog.show(flag,form)
    }
  }
}
</script>
